//package com.software.graduationproject.commons.handler;
//
//import com.alibaba.fastjson.JSON;
//import com.software.graduationproject.commons.enums.ResultCodes;
//import com.software.graduationproject.commons.util.Result;
//import com.software.graduationproject.commons.util.Results;
//import com.software.graduationproject.commons.util.WebUtils;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.web.AuthenticationEntryPoint;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
//import static com.software.graduationproject.commons.enums.ResultCodes.*;
//
//@Component
//public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
//    @Override
//    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
//        Result failure = Results.failure(e.getMessage());
//        failure.setCode(FAILURE_AUTHORIZE_INVALID.getStatus());
//        if (!failure.getMessage().equals(FAILURE_AUTHORIZE_INVALID.getMessage())) {
//            failure.setMessage(FAILURE_AUTHORIZE_EXPIRED.getMessage());
//        }
//        String jsonString = JSON.toJSONString(failure);
//        // 处理认证异常
//        WebUtils.renderString(httpServletResponse, jsonString);
//    }
//}
